/**
 * Author:   YASUO
 * Date:     2018/6/19 17:29
 * Description:
 */
package com.rljk.basecontroller;

import com.github.pagehelper.PageHelper;
import com.rljk.baseservice.BaseCaidanService;
import com.rljk.common.controller.BaseController;
import com.rljk.common.result.CodeMsg;
import com.rljk.common.result.Result;
import com.rljk.utils.AppUtil;
import com.rljk.domain.common.PageData;
import com.rljk.redis.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by YASUO on 2018/6/19.
 */
@RestController
@RequestMapping("/basecaidan")
@Slf4j
public class BaseCaidanController extends BaseController{

    @Resource(name = "baseCaidanService")
    private BaseCaidanService baseCaidanService;

    @Resource(name = "redisService")
    private RedisService redisService;

    @RequestMapping("/list")
    public Object getOne() throws  Exception{
        List<PageData> list = baseCaidanService.findList();
        return Result.success(list);
    }

    @RequestMapping("/getbyid")
    public Object getHeadlinesById() throws  Exception{
        PageData pd = new PageData();
        pd = this.getPageData();

        try {
            //if (Tools.checkKey("WECHATLOGIN", pd.getString("FKEY"))) {
            if (AppUtil.checkParam("wechatlogin", pd)) { // 检查参数
                PageHelper.startPage(1, 2);
                List<PageData> head = baseCaidanService.getHeadlinesById(pd);
                Map<String,Object>map = new HashMap<>();
                map.put("head",head);
                map.put("currentPage",1);
                return Result.success(map);
            } else {
                return Result.error(CodeMsg.PARAM_LACK);
            }
//			} else {
//				return Result.error(CodeMsg.FKEY_FAIL);
//			}
        } catch (Exception e) {
            log.error("错了错了");
            return Result.error(CodeMsg.SERVER_ERROR);
        } finally {
            log.info("afdsdfs");
        }
    }

    @RequestMapping("/setredis")
    public Object setRedis() throws  Exception{
        String set = redisService.set("aaa", "bbb");
        return Result.success(set);
    }

    @RequestMapping("login")
    public Object login() {
        log.info("啊可怜见的撒法艰苦艰苦劳动分局快乐打卡");
        PageData pd = new PageData();
        pd = this.getPageData();
        try {
            //if (Tools.checkKey("WECHATLOGIN", pd.getString("FKEY"))) {
            if (AppUtil.checkParam("wechatlogin", pd)) { // 检查参数

                return Result.success("alkadkdsk");
            } else {
                return Result.error(CodeMsg.PARAM_LACK);
            }
//			} else {
//				return Result.error(CodeMsg.FKEY_FAIL);
//			}
        } catch (Exception e) {
            log.error("错了错了");
            return Result.error(CodeMsg.SERVER_ERROR);
        } finally {
            log.info("afdsdfs");
        }
    }
}
